package com.chookss.view;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chookss.R;
import com.chookss.view.listener.HomeBottomDialogListener;

import io.reactivex.annotations.NonNull;


public class InvitationRegisterBottomDialog extends Dialog {

    private  Context context;
    private HomeBottomDialogListener listener=null;
    private LinearLayout llWechat,llCode,llCopy;
    private RelativeLayout rlAll;
    public InvitationRegisterBottomDialog(@NonNull Context context,HomeBottomDialogListener listener) {
        super(context);
        this.context=context;
        this.listener = listener;
        initLayoutRes();
    }

    public InvitationRegisterBottomDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initLayoutRes();
    }

    private void initLayoutRes() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_invitation_register_bottom, null);
        rlAll=view.findViewById(R.id.rlAll);
        llWechat=view.findViewById(R.id.llWechat);
        llCode=view.findViewById(R.id.llCode);
        llCopy=view.findViewById(R.id.llCopy);
        llWechat.setOnClickListener(v -> {
            if (listener != null) {
                listener.onListItemClick( 0);
            }
            dismiss();
        });
        llCode.setOnClickListener(v -> {
            if (listener != null) {
                listener.onListItemClick( 1);
            }
            dismiss();
        });
        llCopy.setOnClickListener(v -> {
            if (listener != null) {
                listener.onListItemClick( 2);
            }
            dismiss();
        });
        rlAll.setOnClickListener(v -> {
            dismiss();
        });
        setContentView(view);
        initBottom();
    }
    protected void initBottom() {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        Window wm = getWindow();
        lp.width = lp.MATCH_PARENT;
        lp.height = lp.MATCH_PARENT;
        lp.dimAmount = 0.6f;
        wm.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        wm.setGravity(Gravity.BOTTOM);
        wm.setWindowAnimations(R.style.DialogFullWidthDimNotEnabled);
        getWindow().setAttributes(lp);
    }
    protected void safeDismiss() {
        if (isShowing()) {
            dismiss();
        }
    }
}
